﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace FastUtil.Log
{
    public class LogUtil
    {
        /// <summary>
        /// 写入日志，默认根目录的Log文件夹，文件名为log_yyyyMMdd
        /// </summary>
        /// <param name="LogContent">日志内容</param>
        public static void WriteLog(string LogContent)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , "Logs\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", "log_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + LogContent);

                output.Close();
            }

        }

        /// <summary>
        ///  写入日志，默认根目录的Log文件夹
        /// </summary>
        /// <param name="FileName">日志名</param>
        /// <param name="LogContent">日志内容</param>
        public static void WriteLog(string FileName, string LogContent)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , "Logs\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", FileName + "_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + LogContent);

                output.Close();
            }

        }

        /// <summary>
        ///  写入日志
        /// </summary>
        /// <param name="DirPath">日志所属文件夹名称，在根目录创建</param>
        /// <param name="FileName">日志名</param>
        /// <param name="LogContent">日志内容</param>
        public static void WriteLog(string DirPath, string FileName, string LogContent)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            path = System.IO.Path.Combine(path
            , DirPath + "\\");
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            string fileFullName = System.IO.Path.Combine(path, string.Format("{0}.txt", FileName + "_" + DateTime.Now.ToString("yyyyMMdd")));
            using (StreamWriter output = System.IO.File.AppendText(fileFullName))
            {
                output.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + LogContent);

                output.Close();
            }
        }
    }
}
